package cz.muni.fi.pa165.business.service.utils;

import cz.muni.fi.pa165.api.dto.MushroomDTO;
import cz.muni.fi.pa165.business.entity.Months;
import cz.muni.fi.pa165.business.entity.Mushroom;
import cz.muni.fi.pa165.business.entity.MushroomType;

/**
 * Collection of transformation methods between Mushroom and MushroomDTO objects
 *
 * @author Matej Cimbora
 */
public class MushroomObjectTransformer {

    private MushroomObjectTransformer() {
    }

    public static Mushroom mushroomDTOToMushroom(MushroomDTO mushroomDTO) {
        Mushroom mushroom = new Mushroom();
        mushroom.setId(mushroomDTO.getId());
        mushroom.setName(mushroomDTO.getName());
        mushroom.setOccurenceFrom(Months.valueOf(mushroomDTO.getOccurenceFrom().toString()));
        mushroom.setOccurenceTo(Months.valueOf(mushroomDTO.getOccurenceTo().toString()));
        mushroom.setType(MushroomType.valueOf(mushroomDTO.getType().toString()));
        return mushroom;
    }

    public static MushroomDTO mushroomToMushroomDTO(Mushroom mushroom) {
        if (mushroom == null) {
            return null;
        }
        MushroomDTO mushroomDTO = new MushroomDTO();
        mushroomDTO.setId(mushroom.getId());
        mushroomDTO.setName(mushroom.getName());
        mushroomDTO.setOccurenceFrom(MushroomDTO.Months.valueOf(mushroom.getOccurenceFrom().toString()));
        mushroomDTO.setOccurenceTo(MushroomDTO.Months.valueOf(mushroom.getOccurenceTo().toString()));
        mushroomDTO.setType(MushroomDTO.MushroomType.valueOf(mushroom.getType().toString()));
        return mushroomDTO;
    }
}
